/*

*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <wait.h>
#include <sys/types.h>
#include <time.h>

#define MAXSIZE 8192

int main(int argc, char * argv[]) {
	pid_t pid;
	int handle[2];
	char buf[MAXSIZE];

	while((pipe(handle)) == -1) {
		perror("pipe error.");
	}

	while((pid=fork()) == -1) {
		perror("fork error.");
	}

	if(pid == 0) {
		close(handle[1]);
		char c;
		while((read(handle[0], &c, 1) > 0)) {
			if(c>='a' && c<='z')
				c -= 32;
			else if(c>='A' && c<='Z')
				c += 32;
			write(STDOUT_FILENO, &c, 1); 
		}
		exit(EXIT_SUCCESS);
	} else {
		close(handle[0]);
		fgets(buf, MAXSIZE-1, stdin);
		// fscanf(stdin, "%s\n", buf)
		write(handle[1], buf, strlen(buf));
		// wait(0);
		close(handle[1]);
		sleep(1);
	}

	return 0;
}
